[% setvar title Module Scope Control %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>Module Scope Control</p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: Bryan C. Warnock &lt;<a href='mailto:bwarnock@gtemail.net'>bwarnock@gtemail.net</a>&gt;
  Date: 5 Aug 2000
  Last Modified: 28 Sep 2000
  Mailing List: <a href='mailto:perl6-internals@perl.org'>perl6-internals@perl.org</a>
  Number: 40
  Version: 2
  Status: Frozen</pre>
<a name='CHANGES'></a><h1>CHANGES</h1>
<p>Froze.</p>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p>Modules should be able to, internally, control how they (and their
members) are scoped.</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>Hooks should allowed so that module writers can control global and lexical
scoping of its own subs and variables.</p>
<pre>
    package MyModule;
    @globals = qw/$foo $bar %hash @array/;
    @lexicals = qw/$ork $gork @hork $./;
    BEGIN{$. = 834;}
    
    #!/usr/local/bin/perl    
    use MyModule;  # same as use MyModule; local $ork; local $.=834;
    use OtherPackage;
    
    print $MyModule::foo;  # Okay, it exists
    foo() if ($MyModule::$ork);   # Okay, it's scoped here.
    OtherPackage::bar();
    print $.;   # Prints 834.
    
    
    package OtherPackage;
    sub bar {
        print $MyModule::$bar;  # Okay, global.
        print $MyModule::$hork[0];   # Nope, not seen down here.    
        print $.;  Prints whatever it was before 834.  0?
    }</pre>
<a name='MOTIVATORS'></a><h1>MOTIVATORS</h1>
<p>Impatience, and a little laziness.</p>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>I'm not too terribly sure I even got the terminology correct.  Scoping
makes my head hurt.  :-(</p>
<p>I'll concede right now, the above is a mess, and I'd like to find a more
elegant way of handling this.</p>
<p>The point is to allow a module to define (or override) variables only in
the file where <code>use $Module;</code> was invoked.</p>
<p>I thought there was something in Perl 5 that made this easier from a core
perspective, but it seemed to be overly complex for my puny little brain.</p>
<p>This should allow modules to behave like pragmas, in some respects.</p>
<a name='SUMMARY OF IMPLEMENTATION'></a><h2>SUMMARY OF IMPLEMENTATION</h2>
<p>I've no real concrete ideas on this, sorry.  Yes, that's a cop out.  This
seems like one way to handle some of the pragma issues, but I just don't
know enough to make any sort of decent proposal.  Apparently, neither
did anyone else, or maybe this is just so stupid that it wasn't worth
comments.</p>
<a name='IMPACT'></a><h2>IMPACT</h2>
<ul>
<li><a name='Impact on Perl 5. Mutual compatibility between Perl 5 and Perl 6, with the exception of this feature and the sematics it would add. (Obviously, other changes to the language notwithstanding.)'></a>Impact on Perl 5.  Mutual compatibility between Perl 5 and Perl 6, with the
exception of this feature and the sematics it would add.  (Obviously,
other changes to the language notwithstanding.)</li>
</ul>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<p>RFC 2: Request For New Pragma: Implicit</p>
<p>RFC 42: Request For New Pragma: Shell</p>
</div>
